using HKB.Common;
using System;
using System.Data;
using System.Web;
namespace HKB.Web
{
	public class Shop_Bank
	{
		private Conn conn = null;
		private Pagination _pageHand = null;
		protected Pagination pageHand
		{
			get
			{
				Pagination pageHand;
				if (this._pageHand == null)
				{
					this._pageHand = new Pagination();
					this._pageHand.SQL_CloseTablePre = false;
					this._pageHand.P_Object = "银行卡";
					pageHand = this._pageHand;
				}
				else
				{
					pageHand = this._pageHand;
				}
				return pageHand;
			}
		}
		public Shop_Bank(Conn _conn)
		{
			this.conn = _conn;
		}
		public Shop_Bank()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public DataTable GetAllBank(int indexpage, int maxperpage, string wherestr, string orderbystr)
		{
			return this.pageHand.GetDataTable("HLShop_Bank", indexpage, maxperpage, "BankID", wherestr, orderbystr, this.conn, null);
		}
		public string GetPagePanel(string LinkHead)
		{
			this.pageHand.P_LinkHead = LinkHead;
			return this.pageHand.ShowPagePanel();
		}
		public int AddBank(string BankShortName, string BankName, string Accounts, string CardNum, string BankIntro, int UserID, string HolderName)
		{
			return 0;
		}
		public bool DeleteBank(int BankID, int UserID)
		{
			int num;
			if (UserID >= 0)
			{
				num = this.conn.Execute(string.Concat(new object[]
				{
					"DELETE From [HlShop_Bank] Where BankID=",
					BankID,
					" and UserID=",
					UserID
				}));
			}
			else
			{
				num = this.conn.Execute("DELETE From [HlShop_Bank] Where BankID=" + BankID);
			}
			return num == 1;
		}
		public bool DeleteBank(int BankID)
		{
			int num = this.conn.Execute("DELETE From [HlShop_Bank] Where BankID=" + BankID);
			return num == 1;
		}
		public bool UpdateBank(int BankID, string BankName, string Accounts, string CardNum, string BankIntro, string HolderName)
		{
			return false;
		}
		public bool SetDisabled(int BankID)
		{
			bool flag = false;
			DataTable dataTable = this.conn.GetDataTable("Select IsDisabled From [HlShop_Bank] Where BankID=" + BankID);
			bool result;
			if (dataTable.Rows.Count == 0)
			{
				result = false;
			}
			else
			{
				DataRow dataRow = dataTable.Rows[0];
				if (dataRow["IsDisabled"].ToString() == "False")
				{
					flag = true;
				}
				IDbDataParameter dbDataParameter = this.conn.CreateParameter("@IsDisabled", DbType.Boolean, flag);
				int num = this.conn.Execute("UPDATE [HlShop_Bank] Set IsDisabled=@IsDisabled Where BankID=" + BankID, new IDbDataParameter[]
				{
					dbDataParameter
				});
				result = (num == 1);
			}
			return result;
		}
		public bool SetUndefault(int BankID)
		{
			int num = this.conn.Execute("UPDATE [HlShop_Bank] Set IsDefault=0 Where BankID=" + BankID);
			return num == 1;
		}
		public bool SetDefault(int BankID, int UserID)
		{
			int num = this.conn.Execute("UPDATE [HlShop_Bank] Set IsDefault=1 Where BankID=" + BankID);
			return num == 1;
		}
		public DataTable GetBankByID(int BankID)
		{
			return this.conn.GetDataTable("Select * From [HlShop_Bank] Where BankID=" + BankID);
		}
		public DataTable GetBankByUserID(int UserID)
		{
			return this.conn.GetDataTable("Select * From [HlShop_Bank] Where UserID=" + UserID);
		}
		public DataTable GetBankByUserID(int UserID, string ShowType)
		{
			DataTable result;
			if (ShowType != null)
			{
				if (ShowType == "buyer")
				{
					result = this.GetBankByUserID(UserID);
					return result;
				}
				if (ShowType == "saler")
				{
					result = this.conn.GetDataTable("SELECT * FROM HlShop_Bank WHERE IsDisabled=0 AND UserID=" + UserID + " order by IsDefault desc");
					return result;
				}
			}
			result = null;
			return result;
		}
		public DataTable GetBankByBankNameUserID(int UserID, string BankShortName)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@userid", DbType.Int32, UserID),
				this.conn.CreateParameter("@bankshortname", DbType.String, BankShortName)
			};
			return this.conn.GetDataTable("SELECT * FROM HlShop_Bank WHERE (UserID = @userid) AND (BankShortName = @bankshortname)", parameters);
		}
	}
}
